DPGlobal = {
  isLeapYear: function(year) {
    return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
  },
  getDaysInMonth: function(year, month) {
    return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
  },
  dateFormat: function(date, format) {
    var o = {
      "M+": date.getMonth() + 1, //month
      "d+": date.getDate(), //day
      "h+": date.getHours(), //hour
      "m+": date.getMinutes(), //minute
      "s+": date.getSeconds(), //second
      "q+": Math.floor((date.getMonth() + 3) / 3), //quarter
      "S": date.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) {
      format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    for (var k in o) {
      if (new RegExp("(" + k + ")").test(format)) {
        format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
      }
    }
    return format;
  },
  formatDateByUnixtime: function(unixtime) {
    var timestr = new Date(parseInt(unixtime));
    var datetime = DPGlobal.dateFormat(timestr, 'yyyy-MM-dd');
    return datetime;
  }
}


/**
 * @param {String} month 月份 0-11, 0代表1月份
 * @param {String} year 年份 1-12
 */
 function getStartEndDate(year, month) {
  var startDate = new Date(year, month, 1, 0, 0, 0),
      endDate = new Date(year, month, DPGlobal.getDaysInMonth(year, month), 0, 0, 0);
  return {
    startDateStr: DPGlobal.formatDateByUnixtime(startDate.getTime()),
    endDateStr: DPGlobal.formatDateByUnixtime(endDate.getTime())
  };
 }

 export default getStartEndDate;